package com.oceansoft.mobile.biz.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.oceansoft.mobile.biz.api.service.ZzycThread;
import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.util.CacheBaseService;
import com.oceansoft.mobile.common.util.HttpClientUtil;
import com.oceansoft.mobile.common.util.Result;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

/**
 * Created by liujie on 2016/3/31.
 */
@Controller
@RequestMapping("api/zzyc")
public class ApiZzycController {

    final private static String zzycUrl = "http://172.16.3.3/zhcx/ZhcxController";

    /**
     * 自助移车
     *
     * @param request
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "movecar", method = POST)
    public Result submitMoveCarByMyself( HttpServletRequest request, MultipartHttpServletRequest multRequest)
            throws IOException {
        request.getSession().setAttribute("location0", request.getParameter("location0"));
        request.getSession().setAttribute("location1", request.getParameter("location1"));
        request.getSession().setAttribute("remarks", request.getParameter("address"));
        String type= request.getParameter("type");
//        String openId = (String)request.getSession().getAttribute("openId");
//        String validateCode = request.getParameter("validateCode");
//        String aa= CacheBaseService.getInstance().get(request.getParameter("tel")).toString();
//                if(!validateCode.equals(CacheBaseService.getInstance().get(request.getParameter("tel")))){
//                    return new Result(false,"验证码错误！");
//                }
        String pic_data = request.getParameter("picdata");
        String carNo = request.getParameter("carNo");
        if (!StringUtil.isNullOrEmpty(carNo) && 5 == carNo.length()) {
            carNo = "苏E" + carNo;
        }
        JSONObject jsondata = new JSONObject();
        jsondata.put("cplx", request.getParameter("carTypeid"));
        jsondata.put("cphm", carNo);
        jsondata.put("addr", request.getParameter("address"));
        jsondata.put("yhdh", request.getParameter("tel"));

        Map<String, String> paraMap = new HashMap<String, String>();
        paraMap.put("queryId", "DLYC");
        paraMap.put("queryType", "1");
        paraMap.put("requestId", "os");
        paraMap.put("pic", pic_data);
        paraMap.put("params", jsondata.toJSONString());
        JSONObject jsonObject = new JSONObject();
        if(null!=CacheBaseService.getInstance().get(request.getParameter("tel"))){
            jsonObject = JSONObject.parseObject(CacheBaseService.getInstance().get(request.getParameter("tel")));
        }
        return new Result(true,"提交成功！");
    }
}


